from typing import List

from sqlalchemy import create_engine, Boolean, Integer, String, CHAR, ForeignKey, text
from sqlalchemy.orm import declarative_base, relationship
from sqlalchemy.orm import sessionmaker, Mapped, mapped_column
from typing_extensions import Annotated
from app.config import DATABASE_URL
# 引擎
engine = create_engine(DATABASE_URL)
# 引入表格基类
Base = declarative_base()
# 创建session
SessionLocal = sessionmaker(bind=engine) #定义Session类

def get_db():
    session = SessionLocal()
    return session

# 创建别名
# int型主键
INT_PK = Annotated[int, mapped_column(primary_key=True)]
# str型不允许为空
STR_NOTNULL_UNIQUE_20 = Annotated[str, mapped_column(String(20), unique=True,nullable=False)]
# str型不允许为空,长度为20
STR_NOTNULL_20 = Annotated[str, mapped_column(String(20), nullable=False)]

if __name__ == '__main__':
    db = get_db()
    result = db.execute(text("SELECT 1;"))
    print(result)